package com.mmall.concurrency.example.singleton;

import lombok.extern.slf4j.Slf4j;

/**
 * 懒汉模式 运行的时候才被创建
 */
@Slf4j
public class SingletonExample4 {
    private SingletonExample4(){
    }

    /**
     * 1.memory=allocate() 分配对象的内存空间
     * 2。ctorInstance() 初始化对象
     * 3. instance =memory 设置instance指向刚分配的内存
     */
    private  static SingletonExample4 instance=null;

    public static  SingletonExample4 getInstance(){
        if(instance==null){
            synchronized(SingletonExample4.class){
                if(instance==null){
                     instance=new SingletonExample4();

                }
            }
        }
        return instance;
    }
}
